package com.suneee.store.dao.impl;

import java.util.List;
import java.util.Map;

import org.springframework.stereotype.Repository;

import com.suneee.orm.GenericDao;
import com.suneee.store.dao.StockDetailDao;
import com.suneee.store.entity.StockDetail;
import com.suneee.store.resources.StaticParam;

@Repository("stockDetailDao")
public class StockDetailDaoImpl extends GenericDao<StockDetail, Integer>implements StockDetailDao {

	@Override
	public List<StockDetail> selectListByRecordId(String recordId) {
		// TODO Auto-generated method stub
		return this.selectWhere(" record_id = ? ", recordId);
	}

	@Override
	public StockDetail getDetailByRecordIdAndSkuId(String recordId, Integer skuId) {
		// TODO Auto-generated method stub
		List<StockDetail> list = this.selectWhere(" record_id = ? and sku_id = ? ", new Object[]{recordId,skuId});
		if(list == null || list.isEmpty())
			return null;
		return list.get(0);
	}

	@Override
	public List<Map<String, Object>> getOutDetailBySkuId(Integer skuId) {
		// TODO Auto-generated method stub
		String sql = "select de.sku_id as sku_id,re.relevant_store_id as relevant_store_id,sp.`name` as shop_name, "
				+ " de.incoming as stock,re.create_time as create_time "
				+ " FROM t_stock_detail de , t_stock_record re ,t_shop sp "
				+ " WHERE de.record_id = re.record_id "
				+ " and sp.shop_id = re.relevant_store_id"
				+ " and de.sku_id = ? and re.record_type = ? "
				+ " ORDER BY create_time DESC";
		return this.queryForList(sql, new Object[]{skuId,StaticParam.V_STOCK_TYPE_OUT});
	}

}
